package com.baimifan.renovation.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.baimifan.renovation.R;
import com.baimifan.renovation.model.TwoClassifyData;
import com.baimifan.renovation.view.TwoClassifyHolder;

import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by baimifan on 2017/07/04.
 */

public class TwoClassifyAdapter extends RecyclerView.Adapter<TwoClassifyHolder> {
    private ArrayList<TwoClassifyData> mlists;
    private Float w, h;
    public TwoClassifyAdapter (ArrayList<TwoClassifyData> lists, Float w, Float h) {
        this.mlists = lists;
        this.w = w;
        this.h = h;
    }
    @Override
    public TwoClassifyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.two_classify, parent, false);
        TwoClassifyHolder twoClassifyHolder = new TwoClassifyHolder(view);
        return twoClassifyHolder;
    }

    @Override
    public void onBindViewHolder(TwoClassifyHolder holder, int position) {
        LinearLayout.LayoutParams params_iv = new LinearLayout.LayoutParams((int)(w*54), (int)(h*56));
        params_iv.setMargins((int)(w*19), 0, (int)(w*19), (int)(h*10));
        params_iv.gravity = Gravity.CENTER;
        holder.iv.setLayoutParams(params_iv);
        LinearLayout.LayoutParams params_tv = new LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params_tv.gravity = Gravity.CENTER;
        params_tv.setMargins(0, 0, 0, (int)(h*20));
        holder.name.setLayoutParams(params_tv);
        holder.name.setText(mlists.get(position).getCatName());
        x.image().bind(holder.iv, mlists.get(position).getImg());
    }

    @Override
    public int getItemCount() {
        return mlists.size();
    }
}
